<script setup>
import { parseSizeString } from '../../../common/index.js'
import WIcon from '../../w-icon.vue'
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  },
  closable: {
    type: Boolean,
    default: true
  },
  width: {
    type: [String, Number],
    default: 30
  }
})

const emit = defineEmits(['update:modelValue'])

const handleClose = () => {
  emit('update:modelValue', false)
}
</script>

<template>
  <div class="bwy-dialog" @click="handleClose" v-if="modelValue">
    <div
        class="dialog-container"
        :style="{
          width: parseSizeString(width , '%')
        }"
        @click.stop
    >
      <div class="dialog-header">
        <slot name="header"></slot>
        <div v-if="closable" class="dialog-close" @click="handleClose">
          <w-icon name="close" />
        </div>
      </div>
      <div class="dialog-body">
        <slot></slot>
      </div>
      <div class="dialog-footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<style lang="scss">
.bwy-dialog {
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,.3);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  left: 0;
  top: 0;
}
.dialog-container {
  min-height: 240px;
  background: #fff;
  border-radius: 6px;
  margin-top: 120px;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  width: 100%;
  display: flex;
  box-sizing: border-box;
  padding: 16px 24px;
  position: relative;
}
.dialog-body {
  flex: 1;
  box-sizing: border-box;
  padding: 16px 24px;
}
.dialog-footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  box-sizing: border-box;
  padding: 16px 24px;
}
.dialog-close {
  cursor: pointer;
  position: absolute;
  right: 24px;
}
</style>
